package vincent.com.layouttest;

import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

/**
 * Created by zhengwenchen on 2016/5/11.
 */
public class MixColorActivity extends ColorStatusActivity {
    private View color1, color2, colorMixture;

    @Override
    public View onCreateView(ViewGroup rootView) {
        return LayoutInflater.from(this).inflate(R.layout.activity_mix_color, rootView, true);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        color1 = findViewById(R.id.color_1);
        color2 = findViewById(R.id.color_2);

        colorMixture = findViewById(R.id.color_mixture);
    }

    @Override
    public String getToolbarTitle() {
        return "Mix Color";
    }

    public void mixColor(View target){
        int bgColor1 = ((ColorDrawable)color1.getBackground()).getColor();
        int bgColor2 = ((ColorDrawable)color2.getBackground()).getColor();

        int alpha2 = 0xff & (bgColor2>>24);
        int red1 = 0xff & (bgColor1>>16);
        int green1 = 0xff & (bgColor1>>8);
        int blue1 = 0xff & bgColor1;

        int reverseAlpha2 = ~alpha2;
        int newRed1 = reverseAlpha2 & red1;
        int newGreen1 = reverseAlpha2 & green1;
        int newBlue1 = reverseAlpha2 & blue1;

        colorMixture.setBackgroundColor((bgColor1 + bgColor2));
    }
}
